<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{
        list-style: none;
        margin: 0;
        padding: 0;
    }
    div{
        width: 400px;
        height: 200px;
       /* background: #f00; */
       margin: 0 auto;
    }
    div button{
       margin-left: 180px;
    }
    ul{
        margin: 20px auto;
        width: 40px;
        height: 100px;
        border: 1px solid blue;
        font-size: 12px;
        display: none;
    }
    ul li{
        line-height: 30px;
        text-align: center;
    }
    ul .li1{
        border-top: 1px solid blue;
    }
</style>
<body>
    <div>
        <button>输入法</button>
        <ul>
            <li>手写</li>
            <li>拼音</li>
            <li class="li1">关闭</li>
        </ul>
    </div>
</body>
</html>
<script>
    var btn=document.querySelector('button')
    var ul=document.querySelector('ul')
    var lis=document.querySelectorAll('li')
    var lis1=document.querySelector('.li1')
    // var flag=1
    btn.onclick=function(){
           
        //    if(flag == 1){
        //     ul.style.display='block'
        //     flag=0
        //    }else{
        //     ul.style.display='none'
        //     flag=1
        //    }
        if(ul.style.display == 'block'){
            ul.style.display='none'
        }else{
            ul.style.display='block'
        }
    }
    lis1.onclick=function(){
        ul.style.display='none'
    }
    for(var i=0;i<lis.length;i++){
        lis[i].onmouseover=function(){
            this.style.background='red'
        }
        lis[i].onmouseout=function(){
            this.style.background=''
        }
    }
</script>